package com.exp.practice.workbench.controller.teacher;


import com.exp.practice.workbench.domain.Examination;
import com.exp.practice.workbench.domain.ExaminationSituation;
import com.exp.practice.workbench.service.teacher.TeacherAnalyseService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/workbench/teacher/analyse")
public class TeacherAnalyseController {

    @Resource
    private TeacherAnalyseService teacherAnalyseService;

    //获得学生的试卷完成情况
    @RequestMapping("/getFinishedSituation.do")
    @ResponseBody
    public Map<String,Object> getFinishedSituation(String eid){
        Map<String,Object> map=new HashMap<>();
        map=teacherAnalyseService.getFinishedSituation(eid);
        return map;
    }

    //获得某一试卷详情
    @RequestMapping("/getExamination.do")
    @ResponseBody
    public Examination getExamination(String eid){
        Examination examination=new Examination();
        examination=teacherAnalyseService.getExamination(eid);
        return examination;
    }

    //获取该试卷所有已完成学生的答题情况中的姓名和成绩情况
    @RequestMapping("/getExaminationSituation.do")
    @ResponseBody
    public Map<String,Object> getExaminationSituation(String eid){
        Map<String,Object> map=new HashMap<>();
        map=teacherAnalyseService.getExaminationSituation(eid);
        return map;
    }

    //获取该试卷所有已完成学生的答题情况
    @RequestMapping("/getExaminationSituationList.do")
    @ResponseBody
    public List<ExaminationSituation> getExaminationSituationList(String eid){
        List<ExaminationSituation> list=new ArrayList<>();
        list=teacherAnalyseService.getExaminationSituationList(eid);
        return list;
    }


    @RequestMapping("/detail.do")
    public ModelAndView detail(String eid, String stuId, HttpSession session){
        ModelAndView modelAndView=new ModelAndView();
        //获得试卷详情和题目详情
        modelAndView=doTest(eid,session);
        //获得该试卷完成情况
        ExaminationSituation examinationSituation=teacherAnalyseService.getExaminationSituation(eid,stuId);
        modelAndView.addObject("examinationSituation",examinationSituation);
        modelAndView.setViewName("workbench/student/practice/testDetail");
        return modelAndView;
    }

    //获得试卷详情和题目详情
    @RequestMapping("/doTest.do")
    public ModelAndView doTest(String eid, HttpSession session){
        ModelAndView modelAndView=new ModelAndView();
        Map<String,Object> map=new HashMap<>();
        map=teacherAnalyseService.getConcreteExamination(eid);
        modelAndView.addObject("examination",map.get("examination"));
        modelAndView.addObject("questionList",map.get("questionList"));
        session.setAttribute("questionList",map.get("questionList"));
        modelAndView.setViewName("workbench/student/practice/doTest");
        return modelAndView;
    }
}
